1891B - Deja Vu - CodeForces Solution


math sortings

Please click on ads to support us..

C++ Code:

/* KoKo */

#include <bits/stdc++.h>
using namespace std;

#define mod1 1000000007
#define mod2 998244353
#define PI 3.1415926535897932384626433832795
#define ll long long int
#define ull unsigned long long int
#define lld long double
#define all(x) x.begin(), x.end()
#define allr(x) x.rbegin(), x.rend()
#define pb push_back
#define mkp make_pair
#define en endl
#define nl cout << en
#define loop(i, a, b) for (ll i = a; i < b; i++)
#define rloop(i, a, b) for (ll i = a; i >= b; i--)

#ifndef ONLINE_JUDGE
#include "debug.h"
#define debug(x)       \
    cerr << #x << " "; \
    _print(x);         \
    cerr << endl;
#else
#define debug(x) ;
#endif

const ll INF = 1e18;
const ll N = 1e5 + 7;
ll dx[] = { -1, 0, +1, 0};
ll dy[] = {0, +1, 0, -1};
void yes() { cout << "YES\n"; }
void no() { cout << "NO\n"; }
ll max(ll a, ll b) { return (a > b) ? a : b; }
ll min(ll a, ll b) { return (a < b) ? a : b; }
ll ceil(ll a, ll b) { return (a + b - 1) / b; }
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
ll expo(ll a, ll b, ll mod) {ll res = 1; while (b > 0) {if (b & 1)res = (res * a) % mod; a = (a * a) % mod; b = b >> 1;   } return res;}
ll pow(ll a, ll b) {ll res = 1; while (b > 0) {if (b & 1)res = (res * a); a = (a * a); b = b >> 1;   } return res;}
ll mminvprime(ll a, ll b) { return expo(a, b - 2, b); }
ll getBit(ll n, ll ind) { return ((n & (1 << ind)) != 0); }
ll mod_add(ll a, ll b, ll m) { return ((((a % m) + (b % m)) % m) + m) % m; }
ll mod_mul(ll a, ll b, ll m) { return ((((a % m) * (b % m)) % m) + m) % m; }
ll mod_sub(ll a, ll b, ll m) { return ((((a % m) - (b % m)) % m) + m) % m; }
ll mod_div(ll a, ll b, ll m) { return (mod_mul(a % m, mminvprime(b % m, m), m) + m) % m; }
ll fact(ll n) {ll res = 1; loop(i, 1, n + 1) {res = (res * 1ll * i) % mod1;} return res;}
ll ncr(ll n, ll r) {ll cnt1 = 1; loop(i, 0, r) {cnt1 *= (n - i); cnt1 /= (i + 1);} return cnt1;}
ll nCr(ll n, ll k) {return (mod_mul(fact(n), expo(fact(k), mod1 - 2, mod1), mod1) * expo(fact(n - k), mod1 - 2, mod1)) % mod1;}
vector<ll> sieve(ll n) {vector<ll> nums(n + 1); vector<ll> vect; loop(i, 2, n + 1) {if (nums[i] == 0) {vect.pb(i); for (ll j = 2 * i; j <= n; j += i) {nums[j] = 1;}}} return vect;}
bool isPrime(ll n) {if (n == 1) { return false;} loop(i, 2, sqrt(n) + 1) {if (n % i == 0) {return false;}} return true;}
ll getRandomNumber(ll l, ll r) {return uniform_int_distribution<ll>(l, r)(rng);}
void precision(int a) { cout << setprecision(a) << fixed; }
void input(vector<ll> &nums) { for (auto &x : nums) cin >> x; }
void printv(vector<ll> &nums) { for (auto x : nums) cout << x << " "; nl;}
bool cmp(vector<ll> &a, vector<ll> &b) { return a < b; }

void sol()
{
	ll n, k;
	cin >> n >> k;

	vector<ll> v(n), q(k);
	input(v);
	input(q);

	set<ll>s;
	vector<ll> res;
	for (auto &x : q)
	{
		if (s.find(x) == s.end())
		{
			s.insert(x);
			res.push_back(x);
		}
	}

	for (auto &x : res)
	{
		loop(j, 0, n)
		{
			ll r = (1ll << x);
			if (v[j] % r == 0)
			{
				v[j] += r / 2;
			}
		}
	}
	printv(v);
}

int32_t main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);

#ifndef ONLINE_JUDGE
	freopen("inputf.in", "r", stdin);
	freopen("outputf.in", "w", stdout);
	freopen("Error.txt", "w", stderr);
#endif

	ll tc = 1;
	cin >> tc;
	precision(0);

	loop(i, 0, tc)
	{
		sol();
	}
}


Comments

Submit
0 Comments
More Questions

70. Climbing Stairs
53. Maximum Subarray
1527A. And Then There Were K
1689. Partitioning Into Minimum Number Of Deci-Binary Numbers
318. Maximum Product of Word Lengths
448. Find All Numbers Disappeared in an Array
1155. Number of Dice Rolls With Target Sum
415. Add Strings
22. Generate Parentheses
13. Roman to Integer
2. Add Two Numbers
515. Find Largest Value in Each Tree Row
345. Reverse Vowels of a String
628. Maximum Product of Three Numbers
1526A - Mean Inequality
1526B - I Hate 1111
1881. Maximum Value after Insertion
237. Delete Node in a Linked List
27. Remove Element
39. Combination Sum
378. Kth Smallest Element in a Sorted Matrix
162. Find Peak Element
1529A - Eshag Loves Big Arrays
19. Remove Nth Node From End of List
925. Long Pressed Name
1051. Height Checker
695. Max Area of Island
402. Remove K Digits
97. Interleaving String
543. Diameter of Binary Tree